home *** CD-ROM | disk | FTP | other *** search
/ PC Magazine Extra 1998 Summer: The Perfect PC / PC Magazine Extra - The Perfect PC - Summer 1998 Vol 6 #2.iso / dwzdika / 1507 / idincr.prg < prev    next >
Text File  |  1996-01-03  |  2KB  |  51 lines

  1. **************************************************************
  2. * FUNCTION Idincr( cId )
  3. * Increment a character string to the next unique ID using
  4. * the printable characters from chr(33) - chr(126).
  5. * Syntax:  cNewId = Idincr( cId )
  6. **************************************************************
  7. FUNCTION Idincr
  8. PARAMETER cId
  9.  
  10. #DEFINE LoChar 33
  11. #DEFINE HiChar 126
  12. #DEFINE Errchar 27
  13.  
  14. PRIVATE ReturnID, Cpos, CurDigit
  15.  
  16. m.nIdlen = LEN(m.cID)   && Save the length of the id
  17. IF EMPTY(m.cID)
  18.   * Return the beginning ID (just like starting at 1).
  19.   m.ReturnID = REPLICATE( CHR(LoChar), m.nIdlen )
  20. ELSE
  21.   * Start at the beginning, incrementing the first character.
  22.   * If the first character is equal to HiChar, reset it to
  23.   * LoChar and continue to the second character.  Continue in
  24.   * in this fashion until a character is not equal to HiChar (or
  25.   * in the most unusual circumstance, every character in cID is
  26.   * equal to HiChar and is to be replaced with LoChar, essentially
  27.   * exhausting the pool of IDs, in which case we return a string
  28.   * of Errchars.)
  29.   m.ReturnID = m.cID
  30.   m.Cpos = 1
  31.   DO WHILE .T.
  32.     m.CurDigit = ASC( SUBSTR(m.ReturnID,m.Cpos,1) )
  33.     IF m.CurDigit < HiChar
  34.       m.ReturnID = STUFF( m.ReturnID, m.Cpos, 1, CHR(m.CurDigit+1) )
  35.       EXIT
  36.     ELSE
  37.       m.ReturnID = STUFF( m.ReturnID, m.Cpos, 1, CHR(LoChar) )
  38.       m.Cpos = m.Cpos + 1
  39.       IF m.Cpos > m.nIDlen
  40.          m.ReturnID = REPLICATE( CHR(Errchar), m.nIDlen )
  41.          EXIT
  42.       ENDIF
  43.     ENDIF
  44.   ENDDO
  45. ENDIF
  46. RETURN m.ReturnID
  47.  
  48. #UNDEF LoChar
  49. #UNDEF HiChar
  50. #UNDEF Errchar
  51.